package com.main.demo;


import java.util.Scanner;

/**
 * @author admin
 * @version 1.0
 * @date 2019/5/30
 */
public class Person {
    /*存钱*/
    public void save(BandCard card) {
        System.out.println("请输入存款金额：");
        Scanner scanner = new Scanner(System.in);
        Double money = scanner.nextDouble();
        card.setMoney(card.getMoney() + money);
        System.out.println("操作成功，当前余额为：" + card.getMoney());
    }

    /*取钱*/
    public void draw(BandCard card) {
        System.out.println("请输入取款金额：");
        Scanner scanner = new Scanner(System.in);
        Double money = scanner.nextDouble();
        if (card.getMoney() >= money) {
            card.setMoney(card.getMoney() - money);
            System.out.println("操作成功！当前余额剩余：" + card.getMoney());
        } else {
            System.out.println("余额不足，请先存钱！\n 当前余额为：" + card.getMoney());
        }
    }

    /*转账*/
    public void transfer(BandCard srcCard, BandCard[] bandCards, int usedSize) {
        /*设定一个计数器，超过三次则不能进入*/
        int count = 1;
        while (count <= 3) {
            System.out.println("请输入对方账号id:");
            Scanner scanner = new Scanner(System.in);
            int id = scanner.nextInt();
            //遍历银行内的账号，找到目标账号
            for (int i = 0; i < usedSize; i++) {
                if (bandCards[i].getId() == id && bandCards[i].getId() != srcCard.getId()) {
                    System.out.println("请输入转账金额：");
                    Double money = scanner.nextDouble();
                    if (srcCard.getMoney() >= money) {
                        bandCards[i].setMoney(bandCards[i].getMoney() + money);
                        srcCard.setMoney(srcCard.getMoney() - money);
                        System.out.println("转账成功！当前余额剩余："+srcCard.getMoney());
                        return;
                    } else {
                        System.out.println("余额不足，请存钱！");
                    }
                }
            }
            count++;
            System.out.println("请输入对方正确的账号id，您还有" + (3 - count) + "次机会！");
        }
    }

    /*查余额*/
    public void getBalance(BandCard card) {
        System.out.println("当前账户余额为：" + card.getMoney());
    }
}
